import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { fetchCount } from './counterAPI';

//type  0 是根  1 是row  2 是col
class LayoutTreeNode{
  constructor(id,key,parentId,name,layoutType,flexGrow,children,justifyContentVal,alignContentVal)
  {
    this.id=id;  // 数值
    this.key=key;  // 数值
    this.parentId=parentId;  // 数值
    this.name=name;
    this.layoutType=layoutType;
    this.children=children;  // 用数组的方式保存子节点，适合更多业务场景
    //this.flexValue="1 1 auto";
    this.flexGrow=flexGrow;
    this.justifyContent=justifyContentVal;
    this.alignContent=alignContentVal;
    // this.colSpan=colSpan;
    // this.position=position;
  }

  setId(id){
    this.id=id;
  }
  getId(){
    return this.id
  }
  getKey(){
    return this.key
  }
  getName(){
    return this.name
  }
  getParentId(){
    return this.parentId
  }
  getLayoutType(){
    return this.layoutType
  }
  getChildren(){
    return this.children
  }
  getFlexGrow(){
    return this.flexGrow
  }
}

let _children=[];
let layoutTreeNood1 = new LayoutTreeNode("1",1,"0","row1",1,1,[],"center");  //布局树
_children.push(layoutTreeNood1);
let layoutTreeRoot = new LayoutTreeNode("0",0,"-1","root",2,1,_children);  //布局树

const initialStateVal = {
  treeObj: layoutTreeRoot,
  status: 'idle',
};

export const layoutTreeNodeSlice = createSlice({
  name: 'LayoutTreeNode',
  initialState:initialStateVal,
  // The `reducers` field lets us define reducers and generate associated actions
  reducers: {
    addLayoutNode(state, action) { // state是一个代理对象，可以直接修改
      state.username = action.payload;
    },
  },

});
export const { addLayoutNode} = layoutTreeNodeSlice.actions;
export const { reducer: layoutTreeNodeReducer } = layoutTreeNodeSlice;


